<template>
    <div>
        <h1>医生信息添加</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>医生名称</td>
                    <td><input type="text" v-model="qureyInfo.doctorName"></td>
                </tr>
                <tr>
                    <td>医生照片</td>
                    <td>
                        <input type="file" @change="img">
                        <img :src="qureyInfo.photo" alt="" width="60" height="60" v-if="qureyInfo.photo">
                    </td>
                </tr>
                <tr>
                    <td>科室名称</td>
                    <td><select v-model="qureyInfo.departmentName">
                            <option value="">请选择</option>
                            <option :value="item.departmentName" v-for="item in kelist">{{ item.departmentName }}
                            </option>
                        </select></td>
                </tr>
                <tr>
                    <td>职称</td>
                    <td><select v-model="qureyInfo.title">
                            <option value="">请选择</option>
                            <option value="院长">院长</option>
                            <option value="主任医师">主任医师</option>
                            <option value="医师">医师</option>
                            <option value="护士长">护士长</option>
                            <option value="护士">护士</option>
                        </select></td>
                </tr>
                <tr>
                    <td>学历</td>
                    <td><select v-model="qureyInfo.eeuBgr">
                            <option value="">请选择</option>
                            <option value="博士研究生">博士研究生</option>
                            <option value="硕士研究生">硕士研究生</option>
                            <option value="本科">本科</option>
                            <option value="专科">专科</option>
                        </select></td>
                </tr>
                <tr>
                    <td>第一执业医院</td>
                    <td><input type="text" v-model="qureyInfo.hospital"></td>
                </tr>
                <tr>
                    <td>是否开通账号</td>
                    <td>
                        <input type="radio" name="state" value="1" v-model="qureyInfo.state"> 开通
                        <input type="radio" name="state" value="0" v-model="qureyInfo.state"> 未开通
                    </td>
                </tr>
                <tr>
                    <td>类型</td>
                    <td><input type="text" v-model="qureyInfo.types"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-primary" @click="Ok" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();

onMounted(() => {
    getkelist();
})

let kelist: any = ref({});

let qureyInfo: any = reactive({
    "doctorName": "",
    "photo": "",
    "departmentName": "",
    "title": "",
    "eeuBgr": "",
    "hospital": "",
    "state": '',
    "types": "",
})
const getkelist = () => {
    axios({
        url: '/api/Ward/GetDepartment',
        method: 'get',
    })
        .then(res => {
            kelist.value = res.data;
        })
        .catch(err => {

        })
}
//图片上传
const img = (e: any) => {
    let obj = e.target.files[0];
    let f = new FormData();
    f.append('file', obj);
    axios({
        url: '/api/Imgs/Img',
        method: 'post',
        data: f,
    })
        .then(res => {
            if (res.data == "不是图片") {
                alert("你上传的不是图片");
                return;
            }
            if (res.data == "大于2M") {
                alert("你上传的图片大于2M");
                return;
            }
            else {
                qureyInfo.photo = res.data;
                return;
            }

        })
        .catch(err => {

        })
}
const Ok = () => {
    if (qureyInfo.doctorName == "") {
        alert("医生名称不能为空");
        return;
    }
    if (qureyInfo.photo == "") {
        alert("医生照片不能为空");
        return;
    }
    if (qureyInfo.departmentName == "") {
        alert("医生科室不能为空");
        return;
    }
    if (qureyInfo.title == "") {
        alert("医生职称不能为空");
        return;
    }
    if (qureyInfo.eeuBgr == "") {
        alert("医生学历不能为空");
        return;
    }
    if (qureyInfo.hospital == "") {
        alert("第一执业医院不能为空");
        return;
    }
    if (qureyInfo.state == "") {
        alert("状态不能为空");
        return;
    }
    if (qureyInfo.types == "") {
        alert("类型不能为空");
        return;
    }
    axios({
        url: '/api/Ward/DoctorAdd',
        method: 'post',
        data: qureyInfo,
    })
        .then(res => {
            if (res.data > 0) {
                alert("添加成功");
                router.push('/doctorList');
                return;
            }
            else {
                alert("添加失败");
                return;
            }
        })
}
</script>

<style scoped></style>